#include "public_module/file_module/file_handle.h"
#include "public_module/hls_protocol/hls_m3u8_parser.h"

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

int main(int argc, const char * argv[])
{
    std::vector<uint8_t> data_buffer;
    std::string          filename = "./hls.m3u8";
    FileHandle           file_handle(filename);
    int                  ret = file_handle.OpenFileOnlyRead();
    printf("open file result : %d.\n", ret);
    if (ret < 0)
    {
        return EXIT_FAILURE;
    }
    while (true)
    {
        int       length = 0;
        uint8_t * data   = file_handle.Data(length);
        for (int index = 0; index < length; index++)
        {
            data_buffer.push_back(*(data + index));
        }
        if (length == 0)
        {
            break;
        }
        else
        {
            file_handle.RemoveDataLength(length);
        }
    }
    printf("file buffer : %ld.\n", data_buffer.size());
    HlsM3u8Parser parser     = {};
    int           use_length = 0;
    int           result     = parser.Parser(data_buffer.data(), (int)data_buffer.size(), use_length);
    printf("result : %d and data length : %ld use length : %d.\n", result, data_buffer.size(), use_length);
    return EXIT_SUCCESS;
}
